using System;
using System.Threading;
using System.Windows;
using Caliburn.Actions;
using Caliburn.Actions.Filters;

namespace AndyPike.Experiments.Caliburn.Controllers
{
    [Rescue("GeneralRescue")]
    public class CalculatorController
    {
        [Preview("CanDivide")]
        [AsyncAction(BlockInteraction = true)]
        public int Divide(int left, int right)
        {
            Thread.Sleep(3000);

            return left / right;
        }

        public bool CanDivide(int left, int right)
        {
            return right != 0;
        }

        public void GeneralRescue(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}